package com.peng.utils;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;

/**
 * LogParse
 *
 * @author lupeng10
 * @create 2024-03-10 16:09
 */
public class LogParse {

    @Test
    public void t1() throws IOException {
        List<String> strings = FileUtils.readLines(new File("/Users/hou/Downloads/22-1.log"));
        for (String string : strings) {
            try {
                String res = string.split("response:")[1];
                Res resObj = JacksonUtil.fromJson(res, Res.class);
                for (Res.ResultsDTO result : resObj.getResults()) {
                    if (StringUtils.isNotBlank(result.getActionMap().getTipTitle())) {

                    }
                    if (CollectionUtils.isEmpty(result.getActionMap().getCouponArr())) {
                        System.out.println(string);
                        return;
                    }
                }


            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }

    @Test
    public void t2() {
        String s = "aa";
        System.out.println(JacksonUtil.toJson(s));
    }
    @Test
    public void t3() {
        System.out.println(UUID.randomUUID().toString().replaceAll("-", ""));
    }


    @NoArgsConstructor
    @Data
    static class Res {

        @JsonProperty("userId")
        private Long userId;
        @JsonProperty("sceneId")
        private Long sceneId;
        @JsonProperty("results")
        private List<ResultsDTO> results;

        @NoArgsConstructor
        @Data
        public static class ResultsDTO {
            @JsonProperty("nodeId")
            private Long nodeId;
            @JsonProperty("strategyId")
            private Long strategyId;
            @JsonProperty("priority")
            private Integer priority;
            @JsonProperty("actionMap")
            private ActionMapDTO actionMap;

            @NoArgsConstructor
            @Data
            public static class ActionMapDTO {
                @JsonProperty("ganjiRouteAction")
                private String ganjiRouteAction;
                @JsonProperty("smsDynamicParams")
                private List<SmsDynamicParamsDTO> smsDynamicParams;
                @JsonProperty("routeAction")
                private String routeAction;
                @JsonProperty("smsEventId")
                private String smsEventId;
                @JsonProperty("strategyPriority")
                private Integer strategyPriority;
                @JsonProperty("linkType")
                private String linkType;
                @JsonProperty("tipTitle")
                private String tipTitle;
                @JsonProperty("couponArr")
                private List<CouponArrDTO> couponArr;
                @JsonProperty("title")
                private String title;
                @JsonProperty("showLines")
                private String showLines;
                @JsonProperty("couponH5")
                private CouponH5DTO couponH5;

                @NoArgsConstructor
                @Data
                public static class CouponH5DTO {
                    @JsonProperty("buriedParam")
                    private String buriedParam;
                    @JsonProperty("generateH5Flag")
                    private String generateH5Flag;
                }

                @NoArgsConstructor
                @Data
                public static class SmsDynamicParamsDTO {
                    @JsonProperty("dynamicParamType")
                    private String dynamicParamType;
                    @JsonProperty("value")
                    private String value;
                }

                @NoArgsConstructor
                @Data
                public static class CouponArrDTO {
                    @JsonProperty("couponRateLimiterCycle")
                    private String couponRateLimiterCycle;
                    @JsonProperty("couponShowTitle")
                    private String couponShowTitle;
                    @JsonProperty("couponTermType")
                    private String couponTermType;
                    @JsonProperty("couponNeedClick")
                    private String couponNeedClick;
                    @JsonProperty("couponEffectDays")
                    private String couponEffectDays;
                    @JsonProperty("couponShowDiscountNum")
                    private String couponShowDiscountNum;
                    @JsonProperty("couponId")
                    private String couponId;
                    @JsonProperty("couponEffectDays1")
                    private String couponEffectDays1;
                    @JsonProperty("productType")
                    private String productType;
                    @JsonProperty("couponRateLimiterCount")
                    private String couponRateLimiterCount;
                    @JsonProperty("couponShowDiscountUnit")
                    private String couponShowDiscountUnit;
                }
            }
        }
    }

}
